﻿using HdhNetQuery;
using System.Windows;

namespace HdhWpf
{
    /// <summary>
    /// HdhMain.xaml 的交互逻辑
    /// </summary>
    public partial class HdhMain : Window
    {
        public HdhMain()
        {
            if (!HdhcmsDataHelperStatic.TableExists("StudentInfo"))
            {
                string sql = "create table StudentInfo(id int identity(1,1) primary key not null,name nvarchar(20),AddmissionDate datetime )";
                HdhcmsDataHelperStatic.ExecuteNonQuery(sql);
            }

            string strSql = @$"SELECT count(*) FROM sqlite_master 
            WHERE name = 'HdhTable' AND sql LIKE '%HdhField%'";
            strSql = $"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='HdhTable';";
            int countExits = 0;
            object? objValue = HdhcmsDataHelperStatic.ExecuteScalar(strSql);
            if (objValue != null)
            {
                countExits = Convert.ToInt16(objValue);
            }
            if (countExits.Equals(0))
            {
                strSql = "create table HdhTable(id INTEGER PRIMARY KEY AUTOINCREMENT,username varchar(20),password varchar(50))";
                HdhcmsDataHelperStatic.ExecuteNonQuery(strSql);// integer primary key autoincrement 
                strSql = "insert into HdhTable(username,password) values('hdh','123456')";
                HdhcmsDataHelperStatic.ExecuteNonQuery(strSql);
            }
            DataContext = this;
            InitializeComponent();
        }
    }
}
